package com.gdth.bank.activity;

import com.gdth.bank.R;
import com.gdth.bank.adapter.LifeAdapter;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class LifeActivity extends Activity implements OnItemClickListener{
	private int param = 1;
	
	private static final String[] strs = new String[] {
		    "first", "second", "third", "fourth", "fifth"};
	
	ArrayAdapter<?> mArrayAdapter;
	ListView mListView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_life);
		
		initView();
		show(getResources().getString(R.string.param234));
	}
	
	private void initView(){
		mArrayAdapter = new ArrayAdapter<String>(this, 
				android.R.layout.simple_list_item_1, strs);
		
		mListView = (ListView) findViewById(R.id.life_listView);
		
		LifeAdapter mLifeAdapter = new LifeAdapter(this, strs);
		
		mListView.setAdapter(mLifeAdapter);
		//设置点击监听
		mListView.setOnItemClickListener(this);
	}
	
	private void show(String msg){
		new AlertDialog.Builder(this)
		.setMessage(msg)  
		.setPositiveButton("确定", null)
		.show();
	}
	
	@Override
	protected void onStart(){
		super.onStart();
		show("这是开始");
	}
	
	@Override
	protected void onResume(){
		super.onResume();
		show("这是重载");
	}
	
	@Override
	protected void onPause(){
		super.onPause();
		show("这activity被覆盖或是锁屏锁屏时调用");
	}
	
	@Override
	protected void onStop(){
		super.onStop();
		show("这是退出当前Activity或跳转到新的Activity");
	}
	
	@Override
	protected void onDestroy(){
		super.onDestroy();
		show("activity退出结束");
	}
	
	@Override
	protected void onSaveInstanceState(Bundle outState){
		super.onSaveInstanceState(outState);

		outState.putInt("param", param);
		show("屏幕改变方向后"+param);
	}
	
	@Override  
	protected void onRestoreInstanceState(Bundle savedInstanceState) {  
		param = savedInstanceState.getInt("param");  
		super.onRestoreInstanceState(savedInstanceState);  
		show("Activity被系统杀死后再重建时被调用"+param);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		// TODO Auto-generated method stub
		show("你点击了第"+position + strs[position]);
	}  

}
